package com.qb.mobile.util;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

/**
 * @author <a href="mailto:dangcongthanhtrung@gmail.com">dangtrung</a>
 * 
 *         ContactUtils.java class
 * 
 */
public class ContactUtils {

	/**
	 * @param b
	 * @return
	 */
	public static Bitmap ConverterBitmapToByte(byte[] b) {
		return BitmapFactory.decodeByteArray(b, 0, b.length);
	}

	/**
	 * 
	 * @param src
	 * @return
	 */
	public static String convertBitmapToString(Bitmap src) {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		src.compress(android.graphics.Bitmap.CompressFormat.PNG, 100,
				(OutputStream) os);
		return os.toString();
	}

	/**
	 * 
	 * @param src
	 * @return
	 */
	public static Bitmap getBitMapFromString(String src) {
		Log.i("b=", "" + src.getBytes().length);// returns 12111 as a length.
		return BitmapFactory.decodeByteArray(src.getBytes(), 0,
				src.getBytes().length);
	}
}
